﻿<!doctype html>
<html>
<head>
    <meta content="" charset="utf-8" />
    <title>登录页</title>
    <link rel="stylesheet" href="../static/css/adapt.css" />
    <script src="../static/js/jquery-3.3.1.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="page">
        <div class="mainCont clearfix">
            <div class="commLogTit commLogSty" tag="common">普通用户登录</div>
            <div class="conpLogTit commLogSty" tag="conpany">企业用户登录</div>
            <div class="forCommon content" tag="common">
                <input class="listInp username" type="text" placeholder="请输入普通用户名或密码" />
                <input class="listInp pwd" type="password" placeholder="请输入密码" />
                <div class="logBtn" id="logBtn">登录</div>
            </div>
            <div class="forConpany content" tag="conpany">
                <input class="listInp username" type="text" name="username" placeholder="请输入企业用户名或密码" />
                <input class="listInp pwd" type="password" name="password" placeholder="请输入密码" />
                <div class="logBtn" id="logBtn">登录</div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            //加载渲染
            $(".content").eq(1).hide();
            //点击事件
            $(".commLogSty").click(function () {
                var ind = $(this).attr("tag");
                $(".content").hide();
                for (i = 0; i < $(".content").length; i++) {
                    if ($(".content").eq(i).attr("tag") == ind) {
                        $(".content").eq(i).show();
                    }
                }
            })
            //登录事件
            $("#logBtn").click(function () {
                if ($(this).parent($(".content")).find($("input")).val() == "") {
                    alert("用户名和密码不得为空");
                    return;
                }
                var username = $(this).siblings($(".username")).val();
                var pwd = $(this).siblings(".pwd").val();
                $.ajax({
                type: "",
                url: "",
                data: {username:username, password:pwd},
                dataType: "json",
                success: function(data){
                        console.log(data);
                        $('#resText').empty();   //清空resText里面的所有内容
                        var html = '';
                        $.each(data, function(commentIndex, comment){
                              html += '<div class="comment"><h6>' + comment['username']
                                        + ':</h6><p class="para"' + comment['content']
                                        + '</p></div>';
                        });
                        $('#resText').html(html);
                     }
                });
            })
        })
    </script>
</body>
</html>